package com.lei.zjs.service.ebo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.activiti.engine.ProcessEngine;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lei.zjs.dao.WorkordermanageDao;
import com.lei.zjs.service.ebi.WorkordermanageService;
import com.lei.zjs.vo.Workordermanage;

@Service
@Transactional
public class WorkordermanageServiceImpl implements WorkordermanageService {

	@Resource
	private WorkordermanageDao workordermanageDao;
	// 注入流程引擎对象
	@Resource
	private ProcessEngine processEngine;

	@Override
	public void save(Workordermanage model) {
		workordermanageDao.save(model);
	}

	@Override
	public List<Workordermanage> findListNotStart() {
		DetachedCriteria dc = DetachedCriteria.forClass(Workordermanage.class);
		dc.add(Restrictions.eq("start", 0));
		return workordermanageDao.findByCriteria(dc);
	}

	@Override
	public Workordermanage findById(String id) {
		return workordermanageDao.findById(id);
	}

	@Override
	public void start(String id) {
		Workordermanage workordermanage = workordermanageDao.findById(id);
		workordermanage.setStart(1);

		String processDefinitionKey = "transfer";
		Map<String, Object> variables = new HashMap<String, Object>();
		variables.put("业务数据", workordermanage);
		processEngine.getRuntimeService().startProcessInstanceByKey(processDefinitionKey, variables );
	}

	@Override
	public void update(Workordermanage workordermanage) {
		workordermanageDao.update(workordermanage);
	}
}
